<template>
  <j-modal ref="modal" :width="600" :visible="visible" switchFullscreen :title="title" @ok="submit" @cancel="close">
    <a-form-model
      :form="form"
      :model="form"
      ref="ruleForm"
      :rules="rules"
      :label-col="{ span: 4 }"
      :wrapper-col="{ span: 18 }"
    >
      <a-form-model-item label="节点顺序" prop="order">
        {{ order }}
      </a-form-model-item>
      <a-form-model-item label="节点名称" prop="nodeName">
        <a-input placeholder="请填写节点名称" v-model="form.nodeName" />
      </a-form-model-item>
      <!-- <a-form-model-item label="会签关系" prop="approveType"> -->
      <!-- <a-radio-group v-model="form.approveType">
            <a-radio :style="radioStyle" value="01">普通</a-radio>
            <span class="text">只能设置一人作为审核人</span>
            <a-radio :style="radioStyle" value="02">会签</a-radio>
            <span class="text">可设置多人。所有人同意时，流转到下一个审核节点；任一人不同意时，退回指定节点</span>
            <a-radio :style="radioStyle" value="03">或签</a-radio>
            <span class="text">可设置多人。任一人同意时，流转到下一个审核节点；任一人不同意时，退回指定节点 </span>
          </a-radio-group> -->
      <!-- <a-select
            v-model="form.approveType"
            @change="handleApproveType"
            placeholder="请选择会签关系"
          >
            <a-select-option value="01">(普通)关系会签</a-select-option>
            <a-select-option value="02">(或)关系会签</a-select-option>
            <a-select-option value="03">(与)关系会签</a-select-option>
          </a-select>
        </a-form-model-item> -->
      <a-form-model-item label="审核人" prop="approverId">
        <!-- <a-input
            placeholder="选择审核人"
            v-model="form.taskUserName"
            @click="choosePerson()"
          /> -->
        <j-select-user-by-dep v-model="form.approverId" store="id" isDepFiltrate :multi="true" @rows="getSelectRows" />
      </a-form-model-item>
      <!-- <a-form-model-item
          label=""
          style="margin-left:110px;"
          :wrapper-col="{ span: 24 }"
        >
          <a-checkbox v-model="form.expireAction" value="1" />
          超时提醒：
          <a-select allowClear placeholder="请选择流程期限" style="width: 90px">
            <a-select-option
              :value="item.value"
              v-for="(item, index) in times"
              :key="index"
            >
              {{ item.name }}
            </a-select-option>
          </a-select>
          流程超过时期后，每
          <a-select
            :disabled="form.timeLimit == ''"
            placeholder="请选择流程期限"
            style="width: 90px"
          >
            <a-select-option
              :value="item.value"
              v-for="(item, index) in overdueTimes"
              :key="index"
            >
              {{ item.name }}
            </a-select-option>
          </a-select>
          未审核审核，系统提醒一次(当前处理人)
        </a-form-model-item> -->
    </a-form-model>
  </j-modal>
</template>
<script>
const defaultCheckedList = [{ label: '系统通知', value: '1' }]
export default {
  data() {
    return {
      handleType: 'add', // add添加节点，edit编辑节点
      title: null,
      visible: false,
      showDetails: 0,
      order: 1,
      times: [
        { value: '', name: '无' },
        { value: '1小时', name: '1小时' },
        { value: '2小时', name: '2小时' },
        { value: '3小时', name: '3小时' },
        { value: '4小时', name: '4小时' },
        { value: '5小时', name: '5小时' },
        { value: '6小时', name: '6小时' },
        { value: '7小时', name: '7小时' },
        { value: '1天', name: '1天' },
        { value: '2天', name: '2天' },
        { value: '3天', name: '3天' },
        { value: '一周', name: '一周' },
        { value: '10天', name: '10天' },
        { value: '1个月', name: '1个月' }
      ],
      overdueTimes: [
        { value: '', name: '无' },
        { value: '5分钟', name: '5分钟' },
        { value: '10分钟', name: '10分钟' },
        { value: '15分钟', name: '15分钟' },
        { value: '30分钟', name: '30分钟' },
        { value: '45分钟', name: '45分钟' },
        { value: '1小时', name: '1小时' },
        { value: '2小时', name: '2小时' },
        { value: '3小时', name: '3小时' },
        { value: '5小时', name: '5小时' },
        { value: '8小时', name: '8小时' },
        { value: '12小时', name: '12小时' },
        { value: '1天', name: '1天' },
        { value: '2天', name: '2天' },
        { value: '3天', name: '3天' },
        { value: '1周', name: '1周' }
      ],
      peopleLists: [],
      checkedList: defaultCheckedList,
      indeterminate: true,
      checkAll: false,
      value: 1,
      form: {},
      taskNodeInfos: [],
      radioStyle: {
        display: 'block',
        height: '30px',
        lineHeight: '30px'
      },
      rules: {
        nodeName: [{ required: true, message: '请填写节点名称', trigger: 'change' }],
        approveType: [{ required: true, message: '请选择会签关系', trigger: 'change' }],
        approverId: [{ required: true, message: '请选择审核人', trigger: 'change' }]
      },
      datas: []
    }
  },
  props: {
    showFigure: {
      type: Boolean,
      default: true,
      required: false
    }
  },
  methods: {
    submit(e) {
      let vm = this
      this.$refs.ruleForm.validate(async valid => {
        if (valid) {
          vm.$emit('onChildValue', this.handleType, this.form)
          vm.close()
        } else {
          return false
        }
      })
    },
    add() {
      this.handleType = 'add'
      this.title = '添加节点'
      this.visible = true
      this.$nextTick(() => {})
    },
    edit(record) {
      console.log("record")
      console.log(record)
      let form = JSON.parse(JSON.stringify(record))
      this.handleType = 'edit'
      this.title = '编辑节点'
      this.visible = true
      this.form = form
      this.$nextTick(() => {})
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    // 获取审核人信息
    getSelectRows(rows) {
      console.log("rows")
      console.log(rows)
      // 审批人id
      // let approverIds = rows.map(v => v.id).join(',')
      // this.$set(this.form, "approverId", approverIds)
      //审批人名称
      let approverNames = rows.map(v => v.realname).join(',')
      this.$set(this.form, 'approverName', approverNames)
      //部门编号和部门名称
      let orgCode = rows.map(v => v.orgCode).join(',')
      let departName = rows.map(v => v.orgCodeTxt).join(',')
      this.$set(this.form, 'orgCode', orgCode)
      this.$set(this.form, 'departName', departName)
      // 	审批级别
      this.$set(this.form, 'countersignLevel', this.order)
      console.log("this.form")
      console.log(this.form)
    },
    handleApproveType() {
      this.taskNodeInfos = []
      this.$set(this.form, 'childNode', null)
      this.$set(this.form, 'taskUser', '')
      this.$set(this.form, 'taskUserName', '')
    }
  }
}
</script>
